package com.hanlink.dsp.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;

import androidx.annotation.AttrRes;
import androidx.annotation.InspectableProperty;
import androidx.annotation.StyleRes;
/**
 * Copyright (C), 深圳市东乘电子科技有限公司
 * Carate By YangZhong
 */
public class TestFrameLayout extends ViewGroup {




    public TestFrameLayout( Context context) {
        super(context);
    }

    public TestFrameLayout( Context context,  AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TestFrameLayout( Context context, AttributeSet attrs,
                       @AttrRes int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public TestFrameLayout(  Context context, AttributeSet attrs,
                       @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        Button btn = new Button(context);
        btn.setText("aaa");
        btn.setGravity(Gravity.CENTER);
        addView(btn);


    }



    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int count = getChildCount();

        getChildAt(0).measure(MeasureSpec.makeMeasureSpec(700, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(700, MeasureSpec.EXACTLY));

        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);


    }

    protected void measureChildWithMargins(View child,
                                           int parentWidthMeasureSpec, int widthUsed,
                                           int parentHeightMeasureSpec, int heightUsed) {

        child.measure(parentWidthMeasureSpec, parentHeightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
       View view = getChildAt(0);
       view.layout(0,0, view.getMeasuredWidth(), view.getMeasuredHeight());
//        layoutChildren(left, top, right, bottom, false /* no force left gravity */);
    }




}
